package com.music.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.music.server.pojo.*;
import com.music.server.mapper.CollectMapper;
import com.music.server.service.CollectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.music.server.vo.CollectVo;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 收藏 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2021-03-06
 */
@Service
public class CollectServiceImpl extends ServiceImpl<CollectMapper, Collect> implements CollectService {

    @Override
    public Map<String, Object> page(Integer pageNum, Integer size, CollectVo collectVo ) {
        Page<Collect> collectPage = new Page<>(pageNum,size);
        QueryWrapper<Collect> collectQueryWrapper = new QueryWrapper<>();
        if (collectVo.getUserId()!=null){
            collectQueryWrapper.eq("user_id",collectVo.getUserId());
        }
        if (collectVo.getSongId()!=null){
            collectQueryWrapper.eq("song_id",collectVo.getSongId());
        }
        if (collectVo.getSongListId()!=null){
            collectQueryWrapper.eq("song_list_id",collectVo.getSongListId());
        }
        this.page(collectPage,collectQueryWrapper);
        Map<String,Object> data = new HashMap<>();
        data.put("total",collectPage.getTotal());

        List<Collect> collectList = collectPage.getRecords();
        data.put("list",collectList);
        return data;
    }
}
